<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>定时任务管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<script type="text/javascript">
		
		$(function(){
			var roleStr = '${roles}';
			$('#memberRoleList').datagrid({
				title:'会员角色分配列表',
				//iconCls:'icon-ok',
				url:'${ctx}/admin/memberRole/list',
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:false,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				idField:'typeNo',
				columns:[[
                    {field:'typeNo',title:'角色编号',width:200,sortable:true},
					{field:'typeName',title:'角色名称',width:100,sortable:true},
					{field:'opt',title:'是否分配',width:60,sortable:true,
						formatter:function(value,rec){
							var info = "";
							if(roleStr.indexOf(rec.typeNo)< 0){
								info += "<img src=\"${ctx}/js/easyui/themes/default/images/no.png\" id=\""+rec.typeNo+"\" ondblclick=\"memberRoleOpt('"
									+ rec.typeNo
									+ "')\" >";
							}else {
								info += "<img src=\"${ctx}/js/easyui/themes/default/images/yes.png\" id=\""+rec.typeNo+"\" ondblclick=\"memberRoleOpt('"
										+ rec.typeNo
										+ "')\" >";
							}
							return info;
						}
					}
				]]	
			});		
		});
		
		
		function memberRoleOpt(tNo){
			<%request.removeAttribute("roles");%>;
			var srcData = $("#"+tNo).attr("src");
			if(srcData.indexOf("yes")< 0){
				var save_role = '${ctx}/admin/memberRole/save?memberId=${memberId}&typeNo='+tNo;
				$.ajax({
					type: 'POST',
					url: save_role,
					success: function(data){
					  	var oTxt = jQuery.parseJSON(data);
					    var mess = oTxt.msg;	
						var flag = oTxt.flag;
				        if(flag=="T"){
							$.messager.alert('提示',mess, 'info',function(){
								$("#"+tNo).attr("src","${ctx}/js/easyui/themes/default/images/yes.png");
				        	});
						}else{
							$.messager.alert('提示',mess, 'error');
						}
					}
				});
			}else{
				var delete_role = '${ctx}/admin/memberRole/delete?memberId=${memberId}&typeNo='+tNo;
				$.ajax({
					type: 'POST',
					url: delete_role,
					success: function(data){
					  	var oTxt = jQuery.parseJSON(data);
					    var mess = oTxt.msg;	
						var flag = oTxt.flag;
				        if(flag=="T"){
							$.messager.alert('提示',mess, 'info',function(){
								$("#"+tNo).attr("src","${ctx}/js/easyui/themes/default/images/no.png");
				        	});
						}else{
							$.messager.alert('提示',mess, 'error');
						}
					}
				});
			}
			
		}
		
	</script>
</head>
<body>

	<table id="memberRoleList"></table>
	
    
</body>
</html>